import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'dva'
import UserList from './List'

function User({location, dispatch, userTwo, loading}) {

  function onStatusItem(item) {
    dispatch({
      type: 'userTwo/updateStatus',
      payload: {
        curItem: item
      }
    })
  }

  function onSearch(values){
    dispatch({
      type: 'userTwo/search',
      payload: values
    })
  }

  function onCreate(values){
    console.log('index++++++++++',values);
    dispatch({
      type:'userTwo/create',
      payload:values
    })
  }

  function onDeleteItem(id){
    dispatch({
      type:'userTwo/delete',
      payload:id
    })
  }


  const listProps = {
    userTwo,
    loading,
    location,
    onStatusItem,
    onSearch,
    onCreate,
    onDeleteItem,
    dispatch,
  }

  return (
    <div className='content-inner'>

      <UserList {...listProps}/>

    </div>
  );
}

User.propTypes = {
  userTwo: PropTypes.object,
  location: PropTypes.object,
  dispatch: PropTypes.func
};

function mapStateToProps({ userTwo }){
  return { userTwo }
}

export default connect(mapStateToProps)(User);
